Commit 2b092fd3 authored by Eskil Abrahamsen-Blomfeldt's avatar Eskil Abrahamsen-Blomfeldt
Browse files

Qt 5.15 implementation of mouse events

Something off about mouse grabbing. The root item seems to always
grab the event. Easily reproducible with the testscene.qml
parent f22dfa82
......@@ -46,9 +46,10 @@ void QVncItem::registerGeometryChange()
void QVncItem::handleMouse(QMouseEvent *mev)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (!m_remoteInputEnabled)
return;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto da = QQuickItemPrivate::get(this)->deliveryAgent();
//qDebug() << "da" << da << "event" << mev;
......@@ -61,10 +62,14 @@ void QVncItem::handleMouse(QMouseEvent *mev)
da->event(&mappedEvent);
#else
# warning Not implemented mouse support on 5.15
Q_UNUSED(mev);
auto pos = mapToScene(mev->pos());
QMouseEvent mappedEvent(mev->type(), pos, mev->globalPos(), mev->button(), mev->buttons(), mev->modifiers() );
QQuickPointerMouseEvent pointerEvent(this, QQuickPointerDevice::genericMouseDevice());
pointerEvent.reset(&mappedEvent);
QQuickWindowPrivate *wp = QQuickWindowPrivate::get(window());
if (wp != nullptr)
wp->deliverMouseEvent(&pointerEvent);
#endif
}
......@@ -154,6 +159,7 @@ void QVncItem::createServer()
connect(this, &QVncItem::passwordChanged, m_vncServer, &QVncServer::setPassword);
connect(m_vncServer, &QVncServer::isConnectedChanged, this, &QVncItem::setConnectionActive);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(m_vncServer, &QVncServer::mouseEventReceived, this, [this](
QEvent::Type eventType,
const QPointF &mousePosition,
......@@ -164,6 +170,18 @@ void QVncItem::createServer()
QMouseEvent me(eventType, pos, pos, mouseButton, mouseState, keyboardState);
handleMouse(&me);
});
#else
connect(m_vncServer, &QVncServer::mouseEventReceived, this, [this](
int eventType,
const QPointF &mousePosition,
int mouseButton,
int mouseState,
int keyboardState){
QPointF pos(mousePosition.x() / m_uiScale.width(), mousePosition.y() / m_uiScale.height());
QMouseEvent me(QEvent::Type(eventType), pos, pos, Qt::MouseButton(mouseButton), Qt::MouseButtons(mouseState), Qt::KeyboardModifiers(keyboardState));
handleMouse(&me);
});
#endif
connect(m_vncServer, &QVncServer::keyEventReceived, this, [this](
QEvent::Type eventType,
Qt::Key key,
......
......@@ -159,11 +159,19 @@ public:
ProtocolVersion protocolVersion() const { return m_protocolVersion; }
signals:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void mouseEventReceived(QEvent::Type eventType,
const QPointF &mousePosition,
Qt::MouseButton mouseButton,
Qt::MouseButtons mouseState,
Qt::KeyboardModifiers keyboardState);
#else
void mouseEventReceived(int eventType,
const QPointF &mousePosition,
int mouseButton,
int mouseState,
int keyboardState);
#endif
void keyEventReceived(QEvent::Type eventType,
Qt::Key key,
Qt::KeyboardModifiers keyboardModifiers,
......
......@@ -69,11 +69,20 @@ public:
void setPassword(const QByteArray &newPassword);
Q_SIGNALS:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void mouseEventReceived(int eventType,
const QPointF &mousePosition,
int mouseButton,
int mouseState,
int keyboardState);
#else
void mouseEventReceived(QEvent::Type eventType,
const QPointF &mousePosition,
Qt::MouseButton mouseButton,
Qt::MouseButtons mouseState,
Qt::KeyboardModifiers keyboardState);
#endif
void keyEventReceived(QEvent::Type eventType,
Qt::Key key,
Qt::KeyboardModifiers keyboardModifiers,
......
import QtQuick
import QtQuick.Controls
import QtQuickVnc
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.14
import QtQuickVnc 1.0
Window {
width: 1680
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment