summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-31 08:38:16 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-06-16 22:06:56 +0200
commit6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch)
tree61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /src/platformsupport
parent0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (diff)
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does not provide enough information: if it is synthesized, it could have come from any device for which mouse events are synthesized, not only from a touchscreen. By providing in every QInputEvent as complete information about the actual source device as possible, we will enable very fine-tuned behavior in the object that handles each event. Further, we would like to support multiple keyboards, pointing devices, and named groups of devices that are known as "seats" in Wayland. In Qt 5, QPA plugins registered each touchscreen as it was discovered. Now we extend this pattern to all input devices. This new requirement can be implemented gradually; for now, if a QTWSI input event is received wtihout a device pointer, a default "core" device will be created on-the-fly, and a warning emitted. In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when multiple devices were in use simultaneously. Now that each event identifies the device it came from, this hack is no longer needed. A stub of the new QPointerEvent is added; it will be developed further in subsequent patches. [ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer to an instance of QInputDevice, or the subclass QPointingDevice in case of mouse, touch and tablet events. Each platform plugin is expected to create the device instances, register them, and provide valid pointers with all input events. If this is not done, warnings are emitted and default devices are created as necessary. When the device has accurate information, it provides the opportunity to fine-tune behavior depending on device type and capabilities: for example if a QMouseEvent is synthesized from a touchscreen, the recipient can see which touchscreen it came from. Each device also has a seatName to distinguish users on multi-user windowing systems. Touchpoint IDs are no longer unique on their own, but the combination of ID and device is. Fixes: QTBUG-46412 Fixes: QTBUG-72167 Task-number: QTBUG-69433 Task-number: QTBUG-52430 Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp11
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp41
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h12
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp2
-rw-r--r--src/platformsupport/input/libinput/qlibinputtouch.cpp18
-rw-r--r--src/platformsupport/input/libinput/qlibinputtouch_p.h2
6 files changed, 42 insertions, 44 deletions
diff --git a/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp b/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp
index c86840b76c..7ed068c5cc 100644
--- a/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp
+++ b/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp
@@ -42,6 +42,7 @@
#include <QStringList>
#include <QSocketNotifier>
#include <QGuiApplication>
+#include <QPointingDevice>
#include <QLoggingCategory>
#include <QtCore/private/qcore_unix_p.h>
#include <qpa/qwindowsysteminterface.h>
@@ -114,10 +115,10 @@ void QEvdevTabletData::processInputEvent(input_event *ev)
state.down = ev->value != 0;
break;
case BTN_TOOL_PEN:
- state.tool = ev->value ? QTabletEvent::Pen : 0;
+ state.tool = ev->value ? int(QPointingDevice::PointerType::Pen) : 0;
break;
case BTN_TOOL_RUBBER:
- state.tool = ev->value ? QTabletEvent::Eraser : 0;
+ state.tool = ev->value ? int(QPointingDevice::PointerType::Eraser) : 0;
break;
default:
break;
@@ -131,7 +132,7 @@ void QEvdevTabletData::processInputEvent(input_event *ev)
void QEvdevTabletData::report()
{
if (!state.lastReportTool && state.tool)
- QWindowSystemInterface::handleTabletEnterProximityEvent(QTabletEvent::Stylus, state.tool, q->deviceId());
+ QWindowSystemInterface::handleTabletEnterProximityEvent(int(QInputDevice::DeviceType::Stylus), state.tool, q->deviceId());
qreal nx = (state.x - minValues.x) / qreal(maxValues.x - minValues.x);
qreal ny = (state.y - minValues.y) / qreal(maxValues.y - minValues.y);
@@ -150,14 +151,14 @@ void QEvdevTabletData::report()
if (state.down || state.lastReportDown) {
QWindowSystemInterface::handleTabletEvent(0, QPointF(), globalPos,
- QTabletEvent::Stylus, pointer,
+ int(QInputDevice::DeviceType::Stylus), pointer,
state.down ? Qt::LeftButton : Qt::NoButton,
pressure, 0, 0, 0, 0, 0, q->deviceId(),
qGuiApp->keyboardModifiers());
}
if (state.lastReportTool && !state.tool)
- QWindowSystemInterface::handleTabletLeaveProximityEvent(QTabletEvent::Stylus, state.tool, q->deviceId());
+ QWindowSystemInterface::handleTabletLeaveProximityEvent(int(QInputDevice::DeviceType::Stylus), state.tool, q->deviceId());
state.lastReportDown = state.down;
state.lastReportTool = state.tool;
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
index 5f71e7e6a2..5a964c0a17 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
@@ -44,9 +44,9 @@
#include <QHash>
#include <QSocketNotifier>
#include <QGuiApplication>
-#include <QTouchDevice>
#include <QLoggingCategory>
#include <QtCore/private/qcore_unix_p.h>
+#include <QtGui/qpointingdevice.h>
#include <QtGui/private/qhighdpiscaling_p.h>
#include <QtGui/private/qguiapplication_p.h>
@@ -358,7 +358,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const
qUtf16Printable(d->deviceNode), qUtf16Printable(d->m_screenName));
}
- registerTouchDevice();
+ registerPointingDevice();
}
QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler()
@@ -375,7 +375,7 @@ QEvdevTouchScreenHandler::~QEvdevTouchScreenHandler()
delete d;
- unregisterTouchDevice();
+ unregisterPointingDevice();
}
bool QEvdevTouchScreenHandler::isFiltered() const
@@ -383,7 +383,7 @@ bool QEvdevTouchScreenHandler::isFiltered() const
return d && d->m_filtered;
}
-QTouchDevice *QEvdevTouchScreenHandler::touchDevice() const
+QPointingDevice *QEvdevTouchScreenHandler::touchDevice() const
{
return m_device;
}
@@ -444,40 +444,33 @@ err:
QT_CLOSE(m_fd);
m_fd = -1;
- unregisterTouchDevice();
+ unregisterPointingDevice();
}
return;
}
}
}
-void QEvdevTouchScreenHandler::registerTouchDevice()
+void QEvdevTouchScreenHandler::registerPointingDevice()
{
if (m_device)
return;
- m_device = new QTouchDevice;
- m_device->setName(d->hw_name);
- m_device->setType(QTouchDevice::TouchScreen);
- m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area);
+ static int id = 1;
+ QPointingDevice::Capabilities caps = QPointingDevice::Capability::Position | QPointingDevice::Capability::Area;
if (d->hw_pressure_max > d->hw_pressure_min)
- m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure);
+ caps.setFlag(QPointingDevice::Capability::Pressure);
- QWindowSystemInterface::registerTouchDevice(m_device);
+ // TODO get evdev ID instead of an incremeting number; set USB ID too
+ m_device = new QPointingDevice(d->hw_name, id++,
+ QInputDevice::DeviceType::TouchScreen, QPointingDevice::PointerType::Finger,
+ caps, 16, 0);
+ QWindowSystemInterface::registerInputDevice(m_device);
}
-void QEvdevTouchScreenHandler::unregisterTouchDevice()
+void QEvdevTouchScreenHandler::unregisterPointingDevice()
{
- if (!m_device)
- return;
-
- // At app exit the cleanup may have already been done, avoid
- // double delete by checking the list first.
- if (QWindowSystemInterface::isTouchDeviceRegistered(m_device)) {
- QWindowSystemInterface::unregisterTouchDevice(m_device);
- delete m_device;
- }
-
+ delete m_device;
m_device = nullptr;
}
@@ -833,7 +826,7 @@ void QEvdevTouchScreenHandlerThread::run()
m_handler = nullptr;
}
-bool QEvdevTouchScreenHandlerThread::isTouchDeviceRegistered() const
+bool QEvdevTouchScreenHandlerThread::isPointingDeviceRegistered() const
{
return m_touchDeviceRegistered;
}
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h b/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h
index 56308d0352..3ad2602811 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler_p.h
@@ -52,6 +52,7 @@
// We mean it.
//
+//#include <QtGui/qpointingdevice.h>
#include <QtGui/private/qtguiglobal_p.h>
#include <QObject>
#include <QString>
@@ -69,6 +70,7 @@ QT_BEGIN_NAMESPACE
class QSocketNotifier;
class QEvdevTouchScreenData;
+class QPointingDevice;
class QEvdevTouchScreenHandler : public QObject
{
@@ -78,7 +80,7 @@ public:
explicit QEvdevTouchScreenHandler(const QString &device, const QString &spec = QString(), QObject *parent = nullptr);
~QEvdevTouchScreenHandler();
- QTouchDevice *touchDevice() const;
+ QPointingDevice *touchDevice() const;
bool isFiltered() const;
@@ -91,13 +93,13 @@ private:
friend class QEvdevTouchScreenData;
friend class QEvdevTouchScreenHandlerThread;
- void registerTouchDevice();
- void unregisterTouchDevice();
+ void registerPointingDevice();
+ void unregisterPointingDevice();
QSocketNotifier *m_notify;
int m_fd;
QEvdevTouchScreenData *d;
- QTouchDevice *m_device;
+ QPointingDevice *m_device;
#if QT_CONFIG(mtdev)
mtdev *m_mtdev;
#endif
@@ -111,7 +113,7 @@ public:
~QEvdevTouchScreenHandlerThread();
void run() override;
- bool isTouchDeviceRegistered() const;
+ bool isPointingDeviceRegistered() const;
bool eventFilter(QObject *object, QEvent *event) override;
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
index bf2df93d11..a1226ac66a 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
@@ -117,7 +117,7 @@ void QEvdevTouchManager::updateInputDeviceCount()
{
int registeredTouchDevices = 0;
for (const auto &device : m_activeDevices) {
- if (device.handler->isTouchDeviceRegistered())
+ if (device.handler->isPointingDeviceRegistered())
++registeredTouchDevices;
}
diff --git a/src/platformsupport/input/libinput/qlibinputtouch.cpp b/src/platformsupport/input/libinput/qlibinputtouch.cpp
index f00df6b674..c1df7e4c7a 100644
--- a/src/platformsupport/input/libinput/qlibinputtouch.cpp
+++ b/src/platformsupport/input/libinput/qlibinputtouch.cpp
@@ -41,9 +41,11 @@
#include "qtouchoutputmapping_p.h"
#include <libinput.h>
#include <QtGui/QGuiApplication>
+#include <QtGui/QPointingDevice>
#include <QtGui/QScreen>
-#include <QtGui/QTouchDevice>
+#include <QtGui/QPointingDevice>
#include <QtGui/private/qhighdpiscaling_p.h>
+#include <QtGui/private/qpointingdevice_p.h>
QT_BEGIN_NAMESPACE
@@ -107,18 +109,18 @@ void QLibInputTouch::registerDevice(libinput_device *dev)
qPrintable(devNode), qPrintable(m_devState[dev].m_screenName));
}
- QTouchDevice *&td = m_devState[dev].m_touchDevice;
- td = new QTouchDevice;
- td->setName(devName);
- td->setType(QTouchDevice::TouchScreen);
- td->setCapabilities(QTouchDevice::Position | QTouchDevice::Area);
- QWindowSystemInterface::registerTouchDevice(td);
+ QPointingDevice *&td = m_devState[dev].m_touchDevice;
+ td = new QPointingDevice(devName, udev_device_get_devnum(udev_device),
+ QInputDevice::DeviceType::TouchScreen, QPointingDevice::PointerType::Finger,
+ QPointingDevice::Capability::Position | QPointingDevice::Capability::Area, 16, 0);
+ QPointingDevicePrivate::get(td)->busId = QString::fromLocal8Bit(udev_device_get_syspath(udev_device)); // TODO is that the best to choose?
+ QWindowSystemInterface::registerInputDevice(td);
}
void QLibInputTouch::unregisterDevice(libinput_device *dev)
{
Q_UNUSED(dev);
- // There is no way to remove a QTouchDevice.
+ // There is no way to remove a QPointingDevice.
}
void QLibInputTouch::processTouchDown(libinput_event_touch *e)
diff --git a/src/platformsupport/input/libinput/qlibinputtouch_p.h b/src/platformsupport/input/libinput/qlibinputtouch_p.h
index 2682b83b26..175e96f583 100644
--- a/src/platformsupport/input/libinput/qlibinputtouch_p.h
+++ b/src/platformsupport/input/libinput/qlibinputtouch_p.h
@@ -78,7 +78,7 @@ private:
DeviceState() : m_touchDevice(nullptr), m_screenName() { }
QWindowSystemInterface::TouchPoint *point(int32_t slot);
QList<QWindowSystemInterface::TouchPoint> m_points;
- QTouchDevice *m_touchDevice;
+ QPointingDevice *m_touchDevice;
QString m_screenName;
};