From 090d825e1d853a2ed875329a8350b0a727c3527e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 7 Oct 2011 14:54:17 +0200 Subject: Fix QMouse/Wheel/TouchEvent::modifiers with the XCB back-end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The modifiers are provided by X and need to be propagated through the QWindowSystemInterface. Change-Id: I127d0b6e9918b558ca15d9302c4cc0cbd94eb757 Reviewed-on: http://codereview.qt-project.org/6244 Reviewed-by: Laszlo Agocs Sanity-Review: Samuel Rødal Reviewed-by: Samuel Rødal Sanity-Review: Qt Sanity Bot --- src/gui/kernel/qguiapplication.cpp | 8 +++--- src/gui/kernel/qwindowsysteminterface_qpa.cpp | 24 ++++++++--------- src/gui/kernel/qwindowsysteminterface_qpa.h | 12 ++++----- src/gui/kernel/qwindowsysteminterface_qpa_p.h | 38 ++++++++++++++++----------- 4 files changed, 45 insertions(+), 37 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 22443eed80..29b961a170 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -567,7 +567,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo Qt::MouseButtons stateChange = e->buttons ^ buttons; if (e->globalPos != QGuiApplicationPrivate::lastCursorPosition && (stateChange != Qt::NoButton)) { QWindowSystemInterfacePrivate::MouseEvent * newMouseEvent = - new QWindowSystemInterfacePrivate::MouseEvent(e->window.data(), e->timestamp, e->localPos, e->globalPos, e->buttons); + new QWindowSystemInterfacePrivate::MouseEvent(e->window.data(), e->timestamp, e->localPos, e->globalPos, e->buttons, e->modifiers); QWindowSystemInterfacePrivate::windowSystemEventQueue.prepend(newMouseEvent); // just in case the move triggers a new event loop stateChange = Qt::NoButton; } @@ -624,7 +624,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (window) { - QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, QGuiApplication::keyboardModifiers()); + QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers); ev.setTimestamp(e->timestamp); #ifndef QT_NO_CURSOR QList > cursors = QPlatformCursorPrivate::getInstances(); @@ -651,7 +651,7 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh QWindow *window = e->window.data(); if (window) { - QWheelEvent ev(e->localPos, e->globalPos, e->delta, buttons, QGuiApplication::keyboardModifiers(), + QWheelEvent ev(e->localPos, e->globalPos, e->delta, buttons, e->modifiers, e->orient); ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(window, &ev); @@ -894,7 +894,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent touchEvent(eventType, e->devType, - QGuiApplication::keyboardModifiers(), + e->modifiers, it.value().first, it.value().second); touchEvent.setTimestamp(e->timestamp); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index bad1b86935..1745c1bafa 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -114,15 +114,15 @@ void QWindowSystemInterface::handleCloseEvent(QWindow *tlw) */ -void QWindowSystemInterface::handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b) { +void QWindowSystemInterface::handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleMouseEvent(w, time, local, global, b); + handleMouseEvent(w, time, local, global, b, mods); } -void QWindowSystemInterface::handleMouseEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b) +void QWindowSystemInterface::handleMouseEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods) { QWindowSystemInterfacePrivate::MouseEvent * e = - new QWindowSystemInterfacePrivate::MouseEvent(tlw, timestamp, local, global, b); + new QWindowSystemInterfacePrivate::MouseEvent(tlw, timestamp, local, global, b, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } @@ -162,15 +162,15 @@ void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } -void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o) { +void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleWheelEvent(w, time, local, global, d, o); + handleWheelEvent(w, time, local, global, d, o, mods); } -void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o) +void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { QWindowSystemInterfacePrivate::WheelEvent *e = - new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, d, o); + new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, d, o, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } @@ -205,12 +205,12 @@ void QWindowSystemInterfacePrivate::queueWindowSystemEvent(QWindowSystemInterfac dispatcher->wakeUp(); } -void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points) { +void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTouchEvent(w, time, type, devType, points); + handleTouchEvent(w, time, type, devType, points, mods); } -void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points) +void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods) { if (!points.size()) // Touch events must have at least one point return; @@ -245,7 +245,7 @@ void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEv } QWindowSystemInterfacePrivate::TouchEvent *e = - new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, devType, touchPoints); + new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, devType, touchPoints, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 99db5f2b17..0581899500 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -62,8 +62,8 @@ QT_MODULE(Gui) class Q_GUI_EXPORT QWindowSystemInterface { public: - static void handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b); - static void handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b); + static void handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); static void handleKeyEvent(QWindow *w, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); @@ -79,8 +79,8 @@ public: const QString& text = QString(), bool autorep = false, ushort count = 1); - static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o); - static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o); + static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); struct TouchPoint { int id; // for application use @@ -91,8 +91,8 @@ public: Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released} }; - static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points); - static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points); + static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleGeometryChange(QWindow *w, const QRect &newRect); static void handleSynchronousGeometryChange(QWindow *w, const QRect &newRect); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index 77c219737d..121c997e8a 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -134,52 +134,60 @@ public: unsigned long timestamp; }; - class MouseEvent : public UserEvent { + class InputEvent: public UserEvent { public: - MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global, Qt::MouseButtons b) - : UserEvent(w, time, Mouse), localPos(local), globalPos(global), buttons(b) { } + InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods) + : UserEvent(w, time, t), modifiers(mods) {} + Qt::KeyboardModifiers modifiers; + }; + + class MouseEvent : public InputEvent { + public: + MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global, + Qt::MouseButtons b, Qt::KeyboardModifiers mods) + : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b) { } QPointF localPos; QPointF globalPos; Qt::MouseButtons buttons; }; - class WheelEvent : public UserEvent { + class WheelEvent : public InputEvent { public: - WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, int d, Qt::Orientation o) - : UserEvent(w, time, Wheel), delta(d), localPos(local), globalPos(global), orient(o) { } + WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, int d, + Qt::Orientation o, Qt::KeyboardModifiers mods) + : InputEvent(w, time, Wheel, mods), delta(d), localPos(local), globalPos(global), orient(o) { } int delta; QPointF localPos; QPointF globalPos; Qt::Orientation orient; }; - class KeyEvent : public UserEvent { + class KeyEvent : public InputEvent { public: KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1) - :UserEvent(w, time, Key), key(k), unicode(text), repeat(autorep), - repeatCount(count), modifiers(mods), keyType(t), + :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep), + repeatCount(count), keyType(t), nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { } KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, quint32 nativeSC, quint32 nativeVK, quint32 nativeMods, const QString & text = QString(), bool autorep = false, ushort count = 1) - :UserEvent(w, time, Key), key(k), unicode(text), repeat(autorep), - repeatCount(count), modifiers(mods), keyType(t), + :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep), + repeatCount(count), keyType(t), nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { } int key; QString unicode; bool repeat; ushort repeatCount; - Qt::KeyboardModifiers modifiers; QEvent::Type keyType; quint32 nativeScanCode; quint32 nativeVirtualKey; quint32 nativeModifiers; }; - class TouchEvent : public UserEvent { + class TouchEvent : public InputEvent { public: - TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchEvent::DeviceType d, const QList &p) - :UserEvent(w, time, Touch), devType(d), points(p), touchType(t) { } + TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchEvent::DeviceType d, const QList &p, Qt::KeyboardModifiers mods) + :InputEvent(w, time, Touch, mods), devType(d), points(p), touchType(t) { } QTouchEvent::DeviceType devType; QList points; QEvent::Type touchType; -- cgit v1.2.3