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>
This commit is contained in:
Pasi Petäjäjärvi 2019-12-19 13:01:21 +02:00
parent 70d484b5df
commit 6224130cc8
2 changed files with 41 additions and 6 deletions

View File

@ -38,6 +38,7 @@
****************************************************************************/
#include "qlibinputtouch_p.h"
#include "qtouchoutputmapping_p.h"
#include <libinput.h>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
@ -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<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 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);

View File

@ -42,6 +42,7 @@
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QPointer>
#include <qpa/qwindowsysteminterface.h>
//
@ -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<QWindowSystemInterface::TouchPoint> m_points;
QTouchDevice *m_touchDevice;
QString m_screenName;
};
DeviceState *deviceState(libinput_event_touch *e);
QPointF getPos(libinput_event_touch *e);
QHash<libinput_device *, DeviceState> m_devState;
mutable QPointer<QScreen> m_screen;
};
QT_END_NAMESPACE