Client: Don't use deprecated handleMouseEvent version

The new version requires the button that caused the event, as well as the event
type. Instead of adding a conversion functions to and from
QWaylandInputDevice::Type to QEvent::Type, just use QEvent::Type directly, as
there is one-to-one mappings for all the event types we need.

Fixes: QTBUG-80044
Change-Id: I0f6e0e8e7f2e026a1d601f86e819affe0570a1b2
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
Johan Klokkhammer Helsing 2019-10-21 12:02:15 +02:00
parent 84c2b4802f
commit 6111649b41
3 changed files with 46 additions and 45 deletions

View File

@ -630,8 +630,8 @@ class EnterEvent : public QWaylandPointerEvent
{ {
public: public:
EnterEvent(QWaylandWindow *surface, const QPointF &local, const QPointF &global) EnterEvent(QWaylandWindow *surface, const QPointF &local, const QPointF &global)
: QWaylandPointerEvent(QWaylandPointerEvent::Enter, Qt::NoScrollPhase, surface, 0, : QWaylandPointerEvent(QEvent::Enter, Qt::NoScrollPhase, surface, 0,
local, global, nullptr, Qt::NoModifier) local, global, Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{} {}
}; };
@ -675,8 +675,8 @@ class LeaveEvent : public QWaylandPointerEvent
{ {
public: public:
LeaveEvent(QWaylandWindow *surface, const QPointF &localPos, const QPointF &globalPos) LeaveEvent(QWaylandWindow *surface, const QPointF &localPos, const QPointF &globalPos)
: QWaylandPointerEvent(QWaylandPointerEvent::Leave, Qt::NoScrollPhase, surface, 0, : QWaylandPointerEvent(QEvent::Leave, Qt::NoScrollPhase, surface, 0,
localPos, globalPos, nullptr, Qt::NoModifier) localPos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{} {}
}; };
@ -705,8 +705,8 @@ class MotionEvent : public QWaylandPointerEvent
public: public:
MotionEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos, MotionEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Motion, Qt::NoScrollPhase, surface, : QWaylandPointerEvent(QEvent::MouseMove, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, modifiers) timestamp, localPos, globalPos, buttons, Qt::NoButton, modifiers)
{ {
} }
}; };
@ -744,9 +744,10 @@ class PressEvent : public QWaylandPointerEvent
{ {
public: public:
PressEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos, PressEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) const QPointF &globalPos, Qt::MouseButtons buttons, Qt::MouseButton button,
: QWaylandPointerEvent(QWaylandPointerEvent::Press, Qt::NoScrollPhase, surface, Qt::KeyboardModifiers modifiers)
timestamp, localPos, globalPos, buttons, modifiers) : QWaylandPointerEvent(QEvent::MouseButtonPress, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, button, modifiers)
{ {
} }
}; };
@ -755,9 +756,10 @@ class ReleaseEvent : public QWaylandPointerEvent
{ {
public: public:
ReleaseEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos, ReleaseEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) const QPointF &globalPos, Qt::MouseButtons buttons, Qt::MouseButton button,
: QWaylandPointerEvent(QWaylandPointerEvent::Release, Qt::NoScrollPhase, surface, Qt::KeyboardModifiers modifiers)
timestamp, localPos, globalPos, buttons, modifiers) : QWaylandPointerEvent(QEvent::MouseButtonRelease, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, button, modifiers)
{ {
} }
}; };
@ -818,9 +820,9 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
} }
if (state) if (state)
setFrameEvent(new PressEvent(window, time, pos, global, mButtons, mParent->modifiers())); setFrameEvent(new PressEvent(window, time, pos, global, mButtons, qt_button, mParent->modifiers()));
else else
setFrameEvent(new ReleaseEvent(window, time, pos, global, mButtons, mParent->modifiers())); setFrameEvent(new ReleaseEvent(window, time, pos, global, mButtons, qt_button, mParent->modifiers()));
} }
void QWaylandInputDevice::Pointer::invalidateFocus() void QWaylandInputDevice::Pointer::invalidateFocus()
@ -848,7 +850,7 @@ public:
WheelEvent(QWaylandWindow *surface, Qt::ScrollPhase phase, ulong timestamp, const QPointF &local, WheelEvent(QWaylandWindow *surface, Qt::ScrollPhase phase, ulong timestamp, const QPointF &local,
const QPointF &global, const QPoint &pixelDelta, const QPoint &angleDelta, const QPointF &global, const QPoint &pixelDelta, const QPoint &angleDelta,
Qt::MouseEventSource source, Qt::KeyboardModifiers modifiers) Qt::MouseEventSource source, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Wheel, phase, surface, timestamp, : QWaylandPointerEvent(QEvent::Wheel, phase, surface, timestamp,
local, global, pixelDelta, angleDelta, source, modifiers) local, global, pixelDelta, angleDelta, source, modifiers)
{ {
} }
@ -1084,11 +1086,13 @@ void QWaylandInputDevice::Pointer::flushFrameEvent()
if (auto *event = mFrameData.event) { if (auto *event = mFrameData.event) {
if (auto window = event->surface) { if (auto window = event->surface) {
window->handleMouse(mParent, *event); window->handleMouse(mParent, *event);
} else if (mFrameData.event->type == QWaylandPointerEvent::Type::Release) { } else if (mFrameData.event->type == QEvent::MouseButtonRelease) {
// If the window has been destroyed, we still need to report an up event, but it can't // If the window has been destroyed, we still need to report an up event, but it can't
// be handled by the destroyed window (obviously), so send the event here instead. // be handled by the destroyed window (obviously), so send the event here instead.
QWindowSystemInterface::handleMouseEvent(nullptr, event->timestamp, event->local, QWindowSystemInterface::handleMouseEvent(nullptr, event->timestamp, event->local,
event->global, event->buttons, event->modifiers); event->global, event->buttons,
event->button, event->type,
event->modifiers);// , Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
} }
delete mFrameData.event; delete mFrameData.event;
mFrameData.event = nullptr; mFrameData.event = nullptr;

View File

@ -401,29 +401,21 @@ class QWaylandPointerEvent
{ {
Q_GADGET Q_GADGET
public: public:
enum Type { inline QWaylandPointerEvent(QEvent::Type type, Qt::ScrollPhase phase, QWaylandWindow *surface,
Enter,
Leave,
Motion,
Press,
Release,
Wheel
};
Q_ENUM(Type)
inline QWaylandPointerEvent(Type type, Qt::ScrollPhase phase, QWaylandWindow *surface,
ulong timestamp, const QPointF &localPos, const QPointF &globalPos, ulong timestamp, const QPointF &localPos, const QPointF &globalPos,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) Qt::MouseButtons buttons, Qt::MouseButton button,
Qt::KeyboardModifiers modifiers)
: type(type) : type(type)
, phase(phase) , phase(phase)
, timestamp(timestamp) , timestamp(timestamp)
, local(localPos) , local(localPos)
, global(globalPos) , global(globalPos)
, buttons(buttons) , buttons(buttons)
, button(button)
, modifiers(modifiers) , modifiers(modifiers)
, surface(surface) , surface(surface)
{} {}
inline QWaylandPointerEvent(Type type, Qt::ScrollPhase phase, QWaylandWindow *surface, inline QWaylandPointerEvent(QEvent::Type type, Qt::ScrollPhase phase, QWaylandWindow *surface,
ulong timestamp, const QPointF &local, const QPointF &global, ulong timestamp, const QPointF &local, const QPointF &global,
const QPoint &pixelDelta, const QPoint &angleDelta, const QPoint &pixelDelta, const QPoint &angleDelta,
Qt::MouseEventSource source, Qt::MouseEventSource source,
@ -440,12 +432,13 @@ public:
, surface(surface) , surface(surface)
{} {}
Type type; QEvent::Type type = QEvent::None;
Qt::ScrollPhase phase = Qt::NoScrollPhase; Qt::ScrollPhase phase = Qt::NoScrollPhase;
ulong timestamp = 0; ulong timestamp = 0;
QPointF local; QPointF local;
QPointF global; QPointF global;
Qt::MouseButtons buttons; Qt::MouseButtons buttons;
Qt::MouseButton button = Qt::NoButton; // Button that caused the event (QMouseEvent::button)
Qt::KeyboardModifiers modifiers; Qt::KeyboardModifiers modifiers;
QPoint pixelDelta; QPoint pixelDelta;
QPoint angleDelta; QPoint angleDelta;

View File

@ -869,7 +869,7 @@ QWaylandWindow *QWaylandWindow::transientParent() const
void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e) void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e)
{ {
if (e.type == QWaylandPointerEvent::Leave) { if (e.type == QEvent::Leave) {
if (mWindowDecoration) { if (mWindowDecoration) {
if (mMouseEventsInContentArea) if (mMouseEventsInContentArea)
QWindowSystemInterface::handleLeaveEvent(window()); QWindowSystemInterface::handleLeaveEvent(window());
@ -886,24 +886,26 @@ void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, const QWaylan
handleMouseEventWithDecoration(inputDevice, e); handleMouseEventWithDecoration(inputDevice, e);
} else { } else {
switch (e.type) { switch (e.type) {
case QWaylandPointerEvent::Enter: case QEvent::Enter:
QWindowSystemInterface::handleEnterEvent(window(), e.local, e.global); QWindowSystemInterface::handleEnterEvent(window(), e.local, e.global);
break; break;
case QWaylandPointerEvent::Press: case QEvent::MouseButtonPress:
case QWaylandPointerEvent::Release: case QEvent::MouseButtonRelease:
case QWaylandPointerEvent::Motion: case QEvent::MouseMove:
QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, e.local, e.global, e.buttons, e.modifiers); QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, e.local, e.global, e.buttons, e.button, e.type, e.modifiers);
break; break;
case QWaylandPointerEvent::Wheel: case QEvent::Wheel:
QWindowSystemInterface::handleWheelEvent(window(), e.timestamp, e.local, e.global, QWindowSystemInterface::handleWheelEvent(window(), e.timestamp, e.local, e.global,
e.pixelDelta, e.angleDelta, e.modifiers, e.pixelDelta, e.angleDelta, e.modifiers,
e.phase, e.source, false); e.phase, e.source, false);
break; break;
default:
Q_UNREACHABLE();
} }
} }
#if QT_CONFIG(cursor) #if QT_CONFIG(cursor)
if (e.type == QWaylandPointerEvent::Enter) { if (e.type == QEvent::Enter) {
QRect contentGeometry = windowContentGeometry().marginsRemoved(frameMargins()); QRect contentGeometry = windowContentGeometry().marginsRemoved(frameMargins());
if (contentGeometry.contains(e.local.toPoint())) if (contentGeometry.contains(e.local.toPoint()))
restoreMouseCursor(inputDevice); restoreMouseCursor(inputDevice);
@ -947,21 +949,23 @@ void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDe
} }
switch (e.type) { switch (e.type) {
case QWaylandPointerEvent::Enter: case QEvent::Enter:
QWindowSystemInterface::handleEnterEvent(window(), localTranslated, globalTranslated); QWindowSystemInterface::handleEnterEvent(window(), localTranslated, globalTranslated);
break; break;
case QWaylandPointerEvent::Press: case QEvent::MouseButtonPress:
case QWaylandPointerEvent::Release: case QEvent::MouseButtonRelease:
case QWaylandPointerEvent::Motion: case QEvent::MouseMove:
QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, localTranslated, globalTranslated, e.buttons, e.modifiers); QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, localTranslated, globalTranslated, e.buttons, e.button, e.type, e.modifiers);
break; break;
case QWaylandPointerEvent::Wheel: { case QEvent::Wheel: {
QWindowSystemInterface::handleWheelEvent(window(), e.timestamp, QWindowSystemInterface::handleWheelEvent(window(), e.timestamp,
localTranslated, globalTranslated, localTranslated, globalTranslated,
e.pixelDelta, e.angleDelta, e.modifiers, e.pixelDelta, e.angleDelta, e.modifiers,
e.phase, e.source, false); e.phase, e.source, false);
break; break;
} }
default:
Q_UNREACHABLE();
} }
mMouseEventsInContentArea = true; mMouseEventsInContentArea = true;