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 <laszlo.agocs@qt.io>
(cherry picked from commit 6224130cc821b0ef0dbdda80837e872c7996b916)
This commit is contained in:
Pasi Petäjäjärvi 2019-12-19 13:01:21 +02:00
parent 567837a742
commit a649475339
2 changed files with 41 additions and 6 deletions

View File

@ -38,6 +38,7 @@
****************************************************************************/ ****************************************************************************/
#include "qlibinputtouch_p.h" #include "qlibinputtouch_p.h"
#include "qtouchoutputmapping_p.h"
#include <libinput.h> #include <libinput.h>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtGui/QScreen> #include <QtGui/QScreen>
@ -45,6 +46,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(qLcLibInput)
QWindowSystemInterface::TouchPoint *QLibInputTouch::DeviceState::point(int32_t slot) QWindowSystemInterface::TouchPoint *QLibInputTouch::DeviceState::point(int32_t slot)
{ {
const int id = qMax(0, slot); const int id = qMax(0, slot);
@ -62,12 +65,23 @@ QLibInputTouch::DeviceState *QLibInputTouch::deviceState(libinput_event_touch *e
return &m_devState[dev]; 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. DeviceState *state = deviceState(e);
// Perhaps investigate libinput_device_get_output_name as well.
// For now just use the primary screen.
QScreen *screen = QGuiApplication::primaryScreen(); QScreen *screen = QGuiApplication::primaryScreen();
if (!state->m_screenName.isEmpty()) {
if (!m_screen) {
const QList<QScreen *> 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 QRect geom = QHighDpi::toNativePixels(screen->geometry(), screen);
const double x = libinput_event_touch_get_x_transformed(e, geom.width()); const double x = libinput_event_touch_get_x_transformed(e, geom.width());
const double y = libinput_event_touch_get_y_transformed(e, geom.height()); 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) 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; QTouchDevice *&td = m_devState[dev].m_touchDevice;
td = new QTouchDevice; td = new QTouchDevice;
td->setName(QString::fromUtf8(libinput_device_get_name(dev))); td->setName(devName);
td->setType(QTouchDevice::TouchScreen); td->setType(QTouchDevice::TouchScreen);
td->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); td->setCapabilities(QTouchDevice::Position | QTouchDevice::Area);
QWindowSystemInterface::registerTouchDevice(td); QWindowSystemInterface::registerTouchDevice(td);

View File

@ -42,6 +42,7 @@
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QPointer>
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
// //
@ -60,6 +61,7 @@ struct libinput_device;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QScreen;
class QLibInputTouch class QLibInputTouch
{ {
public: public:
@ -73,15 +75,18 @@ public:
private: private:
struct DeviceState { struct DeviceState {
DeviceState() : m_touchDevice(0) { } DeviceState() : m_touchDevice(nullptr), m_screenName() { }
QWindowSystemInterface::TouchPoint *point(int32_t slot); QWindowSystemInterface::TouchPoint *point(int32_t slot);
QList<QWindowSystemInterface::TouchPoint> m_points; QList<QWindowSystemInterface::TouchPoint> m_points;
QTouchDevice *m_touchDevice; QTouchDevice *m_touchDevice;
QString m_screenName;
}; };
DeviceState *deviceState(libinput_event_touch *e); DeviceState *deviceState(libinput_event_touch *e);
QPointF getPos(libinput_event_touch *e);
QHash<libinput_device *, DeviceState> m_devState; QHash<libinput_device *, DeviceState> m_devState;
mutable QPointer<QScreen> m_screen;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE