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:
EnterEvent(QWaylandWindow *surface, const QPointF &local, const QPointF &global)
: QWaylandPointerEvent(QWaylandPointerEvent::Enter, Qt::NoScrollPhase, surface, 0,
local, global, nullptr, Qt::NoModifier)
: QWaylandPointerEvent(QEvent::Enter, Qt::NoScrollPhase, surface, 0,
local, global, Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{}
};
@ -675,8 +675,8 @@ class LeaveEvent : public QWaylandPointerEvent
{
public:
LeaveEvent(QWaylandWindow *surface, const QPointF &localPos, const QPointF &globalPos)
: QWaylandPointerEvent(QWaylandPointerEvent::Leave, Qt::NoScrollPhase, surface, 0,
localPos, globalPos, nullptr, Qt::NoModifier)
: QWaylandPointerEvent(QEvent::Leave, Qt::NoScrollPhase, surface, 0,
localPos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{}
};
@ -705,8 +705,8 @@ class MotionEvent : public QWaylandPointerEvent
public:
MotionEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Motion, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, modifiers)
: QWaylandPointerEvent(QEvent::MouseMove, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, Qt::NoButton, modifiers)
{
}
};
@ -744,9 +744,10 @@ class PressEvent : public QWaylandPointerEvent
{
public:
PressEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Press, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, modifiers)
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::MouseButton button,
Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QEvent::MouseButtonPress, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, button, modifiers)
{
}
};
@ -755,9 +756,10 @@ class ReleaseEvent : public QWaylandPointerEvent
{
public:
ReleaseEvent(QWaylandWindow *surface, ulong timestamp, const QPointF &localPos,
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Release, Qt::NoScrollPhase, surface,
timestamp, localPos, globalPos, buttons, modifiers)
const QPointF &globalPos, Qt::MouseButtons buttons, Qt::MouseButton button,
Qt::KeyboardModifiers 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)
setFrameEvent(new PressEvent(window, time, pos, global, mButtons, mParent->modifiers()));
setFrameEvent(new PressEvent(window, time, pos, global, mButtons, qt_button, mParent->modifiers()));
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()
@ -848,7 +850,7 @@ public:
WheelEvent(QWaylandWindow *surface, Qt::ScrollPhase phase, ulong timestamp, const QPointF &local,
const QPointF &global, const QPoint &pixelDelta, const QPoint &angleDelta,
Qt::MouseEventSource source, Qt::KeyboardModifiers modifiers)
: QWaylandPointerEvent(QWaylandPointerEvent::Wheel, phase, surface, timestamp,
: QWaylandPointerEvent(QEvent::Wheel, phase, surface, timestamp,
local, global, pixelDelta, angleDelta, source, modifiers)
{
}
@ -1084,11 +1086,13 @@ void QWaylandInputDevice::Pointer::flushFrameEvent()
if (auto *event = mFrameData.event) {
if (auto window = event->surface) {
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
// be handled by the destroyed window (obviously), so send the event here instead.
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;
mFrameData.event = nullptr;

View File

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

View File

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