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>
This commit is contained in:
parent
00c09aaf5b
commit
3bf655e596
@ -36,6 +36,25 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*!
|
||||
\class QInputDeviceManager
|
||||
\internal
|
||||
|
||||
\brief QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
|
||||
|
||||
On embedded platforms the input handling code is either compiled into the platform
|
||||
plugin or is loaded dynamically as a generic plugin without any interface. The input
|
||||
handler in use may also change between each run (e.g. evdevmouse/keyboard/touch
|
||||
vs. libinput). QWindowSystemInterface is too limiting when Qt (the platform plugin) is
|
||||
acting as a windowing system, and is one way only.
|
||||
|
||||
QInputDeviceManager solves this by providing a global object that is used to communicate
|
||||
from the input handlers to the rest of Qt (e.g. the number of connected mice, which may
|
||||
be important information for the cursor drawing code), and vice-versa (e.g. to indicate
|
||||
to the input handler that a manual cursor position change was requested by the
|
||||
application via QCursor::setPos and thus any internal state has to be updated accordingly).
|
||||
*/
|
||||
|
||||
QInputDeviceManager::QInputDeviceManager(QObject *parent)
|
||||
: QObject(*new QInputDeviceManagerPrivate, parent)
|
||||
{
|
||||
@ -61,4 +80,9 @@ void QInputDeviceManagerPrivate::setDeviceCount(QInputDeviceManager::DeviceType
|
||||
}
|
||||
}
|
||||
|
||||
void QInputDeviceManager::setCursorPos(const QPoint &pos)
|
||||
{
|
||||
emit cursorPositionChangeRequested(pos);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -68,8 +68,11 @@ public:
|
||||
|
||||
int deviceCount(DeviceType type) const;
|
||||
|
||||
void setCursorPos(const QPoint &pos);
|
||||
|
||||
signals:
|
||||
void deviceListChanged(DeviceType type);
|
||||
void cursorPositionChangeRequested(const QPoint &pos);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -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());
|
||||
|
@ -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,6 +103,21 @@ QEvdevMouseManager::~QEvdevMouseManager()
|
||||
m_mice.clear();
|
||||
}
|
||||
|
||||
void QEvdevMouseManager::clampPosition()
|
||||
{
|
||||
// clamp to screen geometry
|
||||
QRect g = QGuiApplication::primaryScreen()->virtualGeometry();
|
||||
if (m_x + m_xoffset < g.left())
|
||||
m_x = g.left() - m_xoffset;
|
||||
else if (m_x + m_xoffset > g.right())
|
||||
m_x = g.right() - m_xoffset;
|
||||
|
||||
if (m_y + m_yoffset < g.top())
|
||||
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
|
||||
@ -111,17 +129,7 @@ void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButto
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
// clamp to screen geometry
|
||||
QRect g = QGuiApplication::primaryScreen()->virtualGeometry();
|
||||
if (m_x + m_xoffset < g.left())
|
||||
m_x = g.left() - m_xoffset;
|
||||
else if (m_x + m_xoffset > g.right())
|
||||
m_x = g.right() - m_xoffset;
|
||||
|
||||
if (m_y + m_yoffset < g.top())
|
||||
m_y = g.top() - m_yoffset;
|
||||
else if (m_y + m_yoffset > g.bottom())
|
||||
m_y = g.bottom() - m_yoffset;
|
||||
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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -74,6 +74,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onCursorPositionChangeRequested(const QPoint &pos);
|
||||
|
||||
private:
|
||||
void processEvent(libinput_event *ev);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user