From 20a202b11a87d07cf6f3a7bc948c3b54d57ca93f Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 14 Nov 2019 12:50:29 +0000 Subject: [PATCH] [libkwineffects] Construct correct mouse event when forwarding to QtQuickView Summary: Original code (copied from Aurorae) created a QMouseEvent for QHoverEvents. Whilst it apparently worked, it's technically wrong. It's safer to have an explicit type check given we come from a downcast QEvent* and then build the correct event. Test Plan: Hovered some icons Reviewers: #kwin, zzag Reviewed By: #kwin, zzag Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25207 --- libkwineffects/kwineffectquickview.cpp | 34 +++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libkwineffects/kwineffectquickview.cpp b/libkwineffects/kwineffectquickview.cpp index f3d4f876bf..9b61a1e0d0 100644 --- a/libkwineffects/kwineffectquickview.cpp +++ b/libkwineffects/kwineffectquickview.cpp @@ -201,12 +201,34 @@ void EffectQuickView::forwardMouseEvent(QEvent *e) if (!d->m_visible) { return; } - QMouseEvent *me = static_cast(e); - const QPoint widgetPos = d->m_view->mapFromGlobal(me->pos()); - - QMouseEvent cloneEvent(me->type(), widgetPos, me->pos(), me->button(), me->buttons(), me->modifiers()); - QCoreApplication::sendEvent(d->m_view, &cloneEvent); - e->setAccepted(cloneEvent.isAccepted()); + switch (e->type()) { + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + { + QMouseEvent *me = static_cast(e); + const QPoint widgetPos = d->m_view->mapFromGlobal(me->pos()); + QMouseEvent cloneEvent(me->type(), widgetPos, me->pos(), me->button(), me->buttons(), me->modifiers()); + QCoreApplication::sendEvent(d->m_view, &cloneEvent); + e->setAccepted(cloneEvent.isAccepted()); + return; + } + case QEvent::HoverEnter: + case QEvent::HoverLeave: + case QEvent::HoverMove: + { + QHoverEvent *he = static_cast(e); + const QPointF widgetPos = d->m_view->mapFromGlobal(he->pos()); + const QPointF oldWidgetPos = d->m_view->mapFromGlobal(he->oldPos()); + QHoverEvent cloneEvent(he->type(), widgetPos, oldWidgetPos, he->modifiers()); + QCoreApplication::sendEvent(d->m_view, &cloneEvent); + e->setAccepted(cloneEvent.isAccepted()); + return; + } + default: + return; + } } void EffectQuickView::forwardKeyEvent(QKeyEvent *keyEvent)