From 6224130cc821b0ef0dbdda80837e872c7996b916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Thu, 19 Dec 2019 13:01:21 +0200 Subject: Add touch input device mapping support via QT_QPA_EGLFS_KMS_CONFIG To be feature parity with evdev touch which already supports this Change-Id: Ie7f9c868ea888725b24c3855106e1c0c0ba943a9 Reviewed-by: Laszlo Agocs --- .../input/libinput/qlibinputtouch.cpp | 40 +++++++++++++++++++--- .../input/libinput/qlibinputtouch_p.h | 7 +++- 2 files changed, 41 insertions(+), 6 deletions(-) (limited to 'src/platformsupport/input') diff --git a/src/platformsupport/input/libinput/qlibinputtouch.cpp b/src/platformsupport/input/libinput/qlibinputtouch.cpp index ad85360b0e..e1abd44eb5 100644 --- a/src/platformsupport/input/libinput/qlibinputtouch.cpp +++ b/src/platformsupport/input/libinput/qlibinputtouch.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qlibinputtouch_p.h" +#include "qtouchoutputmapping_p.h" #include #include #include @@ -45,6 +46,8 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(qLcLibInput) + QWindowSystemInterface::TouchPoint *QLibInputTouch::DeviceState::point(int32_t slot) { const int id = qMax(0, slot); @@ -62,12 +65,23 @@ QLibInputTouch::DeviceState *QLibInputTouch::deviceState(libinput_event_touch *e return &m_devState[dev]; } -static inline QPointF getPos(libinput_event_touch *e) +QPointF QLibInputTouch::getPos(libinput_event_touch *e) { - // TODO Map to correct screen using QTouchOutputMapping. - // Perhaps investigate libinput_device_get_output_name as well. - // For now just use the primary screen. + DeviceState *state = deviceState(e); QScreen *screen = QGuiApplication::primaryScreen(); + if (!state->m_screenName.isEmpty()) { + if (!m_screen) { + const QList screens = QGuiApplication::screens(); + for (QScreen *s : screens) { + if (s->name() == state->m_screenName) { + m_screen = s; + break; + } + } + } + if (m_screen) + screen = m_screen; + } const QRect geom = QHighDpi::toNativePixels(screen->geometry(), screen); const double x = libinput_event_touch_get_x_transformed(e, geom.width()); const double y = libinput_event_touch_get_y_transformed(e, geom.height()); @@ -76,9 +90,25 @@ static inline QPointF getPos(libinput_event_touch *e) void QLibInputTouch::registerDevice(libinput_device *dev) { + struct udev_device *udev_device; + udev_device = libinput_device_get_udev_device(dev); + QString devNode = QString::fromUtf8(udev_device_get_devnode(udev_device)); + QString devName = QString::fromUtf8(libinput_device_get_name(dev)); + + qCDebug(qLcLibInput, "libinput: registerDevice %s - %s", + qPrintable(devNode), qPrintable(devName)); + + QTouchOutputMapping mapping; + if (mapping.load()) { + m_devState[dev].m_screenName = mapping.screenNameForDeviceNode(devNode); + if (!m_devState[dev].m_screenName.isEmpty()) + qCDebug(qLcLibInput, "libinput: Mapping device %s to screen %s", + qPrintable(devNode), qPrintable(m_devState[dev].m_screenName)); + } + QTouchDevice *&td = m_devState[dev].m_touchDevice; td = new QTouchDevice; - td->setName(QString::fromUtf8(libinput_device_get_name(dev))); + td->setName(devName); td->setType(QTouchDevice::TouchScreen); td->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); QWindowSystemInterface::registerTouchDevice(td); diff --git a/src/platformsupport/input/libinput/qlibinputtouch_p.h b/src/platformsupport/input/libinput/qlibinputtouch_p.h index 51304e6a21..2682b83b26 100644 --- a/src/platformsupport/input/libinput/qlibinputtouch_p.h +++ b/src/platformsupport/input/libinput/qlibinputtouch_p.h @@ -42,6 +42,7 @@ #include #include +#include #include // @@ -60,6 +61,7 @@ struct libinput_device; QT_BEGIN_NAMESPACE +class QScreen; class QLibInputTouch { public: @@ -73,15 +75,18 @@ public: private: struct DeviceState { - DeviceState() : m_touchDevice(nullptr) { } + DeviceState() : m_touchDevice(nullptr), m_screenName() { } QWindowSystemInterface::TouchPoint *point(int32_t slot); QList m_points; QTouchDevice *m_touchDevice; + QString m_screenName; }; DeviceState *deviceState(libinput_event_touch *e); + QPointF getPos(libinput_event_touch *e); QHash m_devState; + mutable QPointer m_screen; }; QT_END_NAMESPACE -- cgit v1.2.3