summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/platformsupport/input')
-rw-r--r--src/platformsupport/input/libinput/qlibinputtouch.cpp40
-rw-r--r--src/platformsupport/input/libinput/qlibinputtouch_p.h7
2 files changed, 41 insertions, 6 deletions
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 <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);
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 <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