diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-03-10 08:29:37 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-03-14 09:24:31 +0000 |
commit | 3bf655e5960c8f0ac4cb8b99a671886b824c7191 (patch) | |
tree | 4f01f8abe022da61ae101ea5e5dc459446973b9b /src/platformsupport | |
parent | 00c09aaf5bac2ae2ee46b20bfbb4b46379ba90e7 (diff) |
Support QCursor::setPos() properly for eglfs
The internal state of the input handlers need updating too. This was not possible
in the past due to the one way communication from the input handlers (that are
potentially loaded as interface-less generic plugins), but using our new private
QInputDeviceManager in QtGui we can now easily implement "talking back" from QtGui
to the input handlers, regardless of them being plugins or compiled in.
The rest of setPos() is in place already for eglfs.
linuxfb will be handled in follow-up patches.
Task-number: QTBUG-44856
Change-Id: Id72fdb8b1ea176ddfe082e466e7a538a2a98a005
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/platformsupport')
7 files changed, 47 insertions, 10 deletions
diff --git a/src/platformsupport/eglconvenience/qeglplatformcursor.cpp b/src/platformsupport/eglconvenience/qeglplatformcursor.cpp index 5023efbaf6..09243487c7 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcursor.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcursor.cpp @@ -298,6 +298,7 @@ QPoint QEGLPlatformCursor::pos() const void QEGLPlatformCursor::setPos(const QPoint &pos) { + QGuiApplicationPrivate::inputDeviceManager()->setCursorPos(pos); const QRect oldCursorRect = cursorRect(); m_cursor.pos = pos; update(oldCursorRect | cursorRect()); diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 6eb1fccba0..805397f021 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -92,6 +92,9 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeMouse(QString))); } } + + connect(QGuiApplicationPrivate::inputDeviceManager(), SIGNAL(cursorPositionChangeRequested(QPoint)), + this, SLOT(handleCursorPositionChange(QPoint))); } QEvdevMouseManager::~QEvdevMouseManager() @@ -100,17 +103,8 @@ QEvdevMouseManager::~QEvdevMouseManager() m_mice.clear(); } -void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons) +void QEvdevMouseManager::clampPosition() { - // update current absolute coordinates - if (!abs) { - m_x += x; - m_y += y; - } else { - m_x = x; - m_y = y; - } - // clamp to screen geometry QRect g = QGuiApplication::primaryScreen()->virtualGeometry(); if (m_x + m_xoffset < g.left()) @@ -122,6 +116,20 @@ void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButto m_y = g.top() - m_yoffset; else if (m_y + m_yoffset > g.bottom()) m_y = g.bottom() - m_yoffset; +} + +void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons) +{ + // update current absolute coordinates + if (!abs) { + m_x += x; + m_y += y; + } else { + m_x = x; + m_y = y; + } + + clampPosition(); QPoint pos(m_x + m_xoffset, m_y + m_yoffset); // Cannot track the keyboard modifiers ourselves here. Instead, report the @@ -163,4 +171,11 @@ void QEvdevMouseManager::removeMouse(const QString &deviceNode) } } +void QEvdevMouseManager::handleCursorPositionChange(const QPoint &pos) +{ + m_x = pos.x(); + m_y = pos.y(); + clampPosition(); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h index 944effd80b..e1b24b807d 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h @@ -69,8 +69,11 @@ public slots: private slots: void addMouse(const QString &deviceNode = QString()); void removeMouse(const QString &deviceNode); + void handleCursorPositionChange(const QPoint &pos); private: + void clampPosition(); + QString m_spec; QHash<QString,QEvdevMouseHandler*> m_mice; QDeviceDiscovery *m_deviceDiscovery; diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp index 22b08960df..1a64ad5a30 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp @@ -107,6 +107,9 @@ QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec) m_keyboard.reset(new QLibInputKeyboard); m_touch.reset(new QLibInputTouch); + connect(QGuiApplicationPrivate::inputDeviceManager(), SIGNAL(cursorPositionChangeRequested(QPoint)), + this, SLOT(onCursorPositionChangeRequested(QPoint))); + // Process the initial burst of DEVICE_ADDED events. onReadyRead(); } @@ -227,4 +230,9 @@ void QLibInputHandler::processEvent(libinput_event *ev) } } +void QLibInputHandler::onCursorPositionChangeRequested(const QPoint &pos) +{ + m_pointer->setPos(pos); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/libinput/qlibinputhandler_p.h b/src/platformsupport/input/libinput/qlibinputhandler_p.h index 5d54f984de..de04d71f93 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler_p.h +++ b/src/platformsupport/input/libinput/qlibinputhandler_p.h @@ -74,6 +74,7 @@ signals: private slots: void onReadyRead(); + void onCursorPositionChangeRequested(const QPoint &pos); private: void processEvent(libinput_event *ev); diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp index 794ac54e8e..48e5a6cf1c 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer.cpp +++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp @@ -108,4 +108,11 @@ void QLibInputPointer::processAxis(libinput_event_pointer *e) #endif } +void QLibInputPointer::setPos(const QPoint &pos) +{ + const QRect g = QGuiApplication::primaryScreen()->virtualGeometry(); + m_pos.setX(qBound(g.left(), pos.x(), g.right())); + m_pos.setY(qBound(g.top(), pos.y(), g.bottom())); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/libinput/qlibinputpointer_p.h b/src/platformsupport/input/libinput/qlibinputpointer_p.h index 3b0c5df1c6..a8ba19c7ec 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer_p.h +++ b/src/platformsupport/input/libinput/qlibinputpointer_p.h @@ -60,6 +60,8 @@ public: void processMotion(libinput_event_pointer *e); void processAxis(libinput_event_pointer *e); + void setPos(const QPoint &pos); + private: QPoint m_pos; Qt::MouseButtons m_buttons; |