summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2017-08-30 11:03:39 +0200
committerGatis Paeglis <gatis.paeglis@qt.io>2017-10-10 22:09:07 +0000
commita37785ec7638e7485112b87dd7e767881fecc114 (patch)
treec238af4d154c12e80532daff5245627b181f5d40 /src/platformsupport
parent0900cf3581be3ff2b2e924ce0d845566c5df841e (diff)
qpa: enhance mouse event with type and button data
... and deprecate QWSI APIs that accepts mouse event without mouse button/ type data. In the early days of Qt5 it was decided to centralize mouse button/type handling in QGuiApplication (because of limitation of some now unknown platform). This has proven to be problematic as mouse handling details differ across platforms (e.g on X11 we do not receive mouse release event when closing popup windows or ordinary windows that are closed from the mouse press event). Instead of hacking around platform specific behaviors in Qt Gui, we should move this task back to platform plugins (similar to how this was done in Qt4 with native APIs sending mouse details directly to QApplication). There are even cases where it simply is not possible to deduce (from QGuiApplication) which button caused the event (e.g. when more than one button is involved and some event goes missing). Besisdes, throwing away information which is already available at QPA level (for free) and trying to deduce it again at Qt Gui level seems impractical, fagile (as probably noticed by people fixing all the unexpected issues) and adds unnecessary complexity. Note: Removing the deprecated QWSI APIs from offscreen plugin depends on fixing autotests that rely on QOffscreenCursor::setPos() logic. For the convenience of testing use QT_QPA_DISABLE_ENHANCED_MOUSE to restore to the old code path where QGuiApplication does the mouse state deducing. Other platforms have similar issues. I do not have all supported platform available on my desk, so other platform maintainers will need to take care of porting those platforms to the new APIs. And mainly, I don't want to deal with all the hacks that other platforms have added to workaround this broken mouse logic. In Qt6 we need to remove deprecated code path from QGuiApplication. This patch: - Extends QWindowSystemInterfacePrivate::MouseEvent ctor with QEvent::Type and Qt::MouseButton. We use this extra data when processing mouse events in QGuiApplication. This actually is similar to KeyEvent, where we do pass the type (press or release) to QtGui. - Refactors QGuiApplicationPrivate::processMouseEvent and qtestlib to use the new APIs. Task-number: QTBUG-59277 Task-number: QTBUG-62329 Task-number: QTBUG-63467 Change-Id: If94fd46a7cccfea8264dcb1368804c73334558b8 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp5
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h6
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp6
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h3
-rw-r--r--src/platformsupport/input/libinput/qlibinputpointer.cpp11
5 files changed, 24 insertions, 7 deletions
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
index cd7eec3861..04372ae4d9 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
@@ -184,7 +184,7 @@ void QEvdevMouseHandler::sendMouseEvent()
m_prevInvalid = false;
}
- emit handleMouseEvent(x, y, m_abs, m_buttons);
+ emit handleMouseEvent(x, y, m_abs, m_buttons, m_button, m_eventType);
m_prevx = m_x;
m_prevy = m_y;
@@ -286,6 +286,8 @@ void QEvdevMouseHandler::readMouseData()
case 0x11f: button = Qt::ExtraButton13; break;
}
m_buttons.setFlag(button, data->value);
+ m_button = button;
+ m_eventType = data->value == 0 ? QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
btnChanged = true;
} else if (data->type == EV_SYN && data->code == SYN_REPORT) {
if (btnChanged) {
@@ -293,6 +295,7 @@ void QEvdevMouseHandler::readMouseData()
sendMouseEvent();
pendingMouseEvent = false;
} else if (posChanged) {
+ m_eventType = QEvent::MouseMove;
posChanged = false;
if (m_compression) {
pendingMouseEvent = true;
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
index 6cad4b9173..c7f2b04eb2 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
+++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
@@ -54,6 +54,7 @@
#include <QObject>
#include <QString>
#include <QPoint>
+#include <QEvent>
QT_BEGIN_NAMESPACE
@@ -69,7 +70,8 @@ public:
void readMouseData();
signals:
- void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons);
+ void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
+ Qt::MouseButton button, QEvent::Type type);
void handleWheelEvent(QPoint delta);
private:
@@ -86,6 +88,8 @@ private:
bool m_abs;
bool m_compression;
Qt::MouseButtons m_buttons;
+ Qt::MouseButton m_button;
+ QEvent::Type m_eventType;
int m_jitterLimitSquared;
bool m_prevInvalid;
int m_hardwareWidth;
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
index ba94bcd460..5264736dd6 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
@@ -131,7 +131,8 @@ void QEvdevMouseManager::clampPosition()
m_y = g.bottom() - m_yoffset;
}
-void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons)
+void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
+ Qt::MouseButton button, QEvent::Type type)
{
// update current absolute coordinates
if (!abs) {
@@ -147,7 +148,8 @@ void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButto
QPoint pos(m_x + m_xoffset, m_y + m_yoffset);
// Cannot track the keyboard modifiers ourselves here. Instead, report the
// modifiers from the last key event that has been seen by QGuiApplication.
- QWindowSystemInterface::handleMouseEvent(0, pos, pos, buttons, QGuiApplication::keyboardModifiers());
+ Qt::KeyboardModifiers mods = QGuiApplication::keyboardModifiers();
+ QWindowSystemInterface::handleMouseEvent(0, pos, pos, buttons, button, type, mods);
}
void QEvdevMouseManager::handleWheelEvent(QPoint delta)
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h
index 10703655b3..13a8e3dec5 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h
+++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h
@@ -68,7 +68,8 @@ public:
QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0);
~QEvdevMouseManager();
- void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons);
+ void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons,
+ Qt::MouseButton button, QEvent::Type type);
void handleWheelEvent(QPoint delta);
void addMouse(const QString &deviceNode = QString());
diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp
index d85a01b7d7..12379a83fa 100644
--- a/src/platformsupport/input/libinput/qlibinputpointer.cpp
+++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp
@@ -39,6 +39,7 @@
#include "qlibinputpointer_p.h"
#include <libinput.h>
+#include <QtCore/QEvent>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <qpa/qwindowsysteminterface.h>
@@ -78,7 +79,10 @@ void QLibInputPointer::processButton(libinput_event_pointer *e)
m_buttons.setFlag(button, pressed);
- QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons, QGuiApplication::keyboardModifiers());
+ QEvent::Type type = pressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease;
+ Qt::KeyboardModifiers mods = QGuiApplication::keyboardModifiers();
+
+ QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons, button, type, mods);
}
void QLibInputPointer::processMotion(libinput_event_pointer *e)
@@ -91,7 +95,10 @@ void QLibInputPointer::processMotion(libinput_event_pointer *e)
m_pos.setX(qBound(g.left(), qRound(m_pos.x() + dx), g.right()));
m_pos.setY(qBound(g.top(), qRound(m_pos.y() + dy), g.bottom()));
- QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons, QGuiApplication::keyboardModifiers());
+ Qt::KeyboardModifiers mods = QGuiApplication::keyboardModifiers();
+
+ QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons,
+ Qt::NoButton, QEvent::MouseMove, mods);
}
void QLibInputPointer::processAxis(libinput_event_pointer *e)