Commit 20a202b1 authored by David Edmundson's avatar David Edmundson
Browse files

[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
parent 6dfb7ba1
......@@ -201,12 +201,34 @@ void EffectQuickView::forwardMouseEvent(QEvent *e)
if (!d->m_visible) {
return;
}
QMouseEvent *me = static_cast<QMouseEvent *>(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<QMouseEvent *>(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<QHoverEvent *>(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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment