mousepad: Support setting the cursor to absolute positions

This commit is contained in:
David Redondo 2024-06-24 10:49:57 +02:00
parent 551af5fcac
commit b7763fc888
4 changed files with 34 additions and 11 deletions

View file

@ -71,6 +71,8 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
float dx = np.get<float>(QStringLiteral("dx"), 0);
float dy = np.get<float>(QStringLiteral("dy"), 0);
float x = np.get<float>(QStringLiteral("x"), 0);
float y = np.get<float>(QStringLiteral("y"), 0);
bool isSingleClick = np.get<bool>(QStringLiteral("singleclick"), false);
bool isDoubleClick = np.get<bool>(QStringLiteral("doubleclick"), false);
@ -214,8 +216,12 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
}
} else { //Is a mouse move event
if (dx || dy) {
QPoint point = QCursor::pos();
QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
} else if (np.has(QStringLiteral("x")) || np.has(QStringLiteral("y"))) {
QCursor::setPos(x, y);
}
}
return true;
}

View file

@ -210,6 +210,8 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
const float dx = np.get<float>(QStringLiteral("dx"), 0);
const float dy = np.get<float>(QStringLiteral("dy"), 0);
const float x = np.get<float>(QStringLiteral("x"), 0);
const float y = np.get<float>(QStringLiteral("y"), 0);
const bool isSingleClick = np.get<bool>(QStringLiteral("singleclick"), false);
const bool isDoubleClick = np.get<bool>(QStringLiteral("doubleclick"), false);
@ -283,7 +285,10 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
s_session->iface->NotifyKeyboardKeycode(s_session->m_xdpPath, {}, KEY_LEFTMETA, 0);
}
} else { // Is a mouse move event
if (dx || dy)
s_session->iface->NotifyPointerMotion(s_session->m_xdpPath, {}, dx, dy);
else if ((np.has(QStringLiteral("x")) || np.has(QStringLiteral("y"))))
s_session->iface->NotifyPointerMotionAbsolute(s_session->m_xdpPath, {}, 0, x, y);
}
return true;
}

View file

@ -64,6 +64,8 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np)
{
float dx = np.get<float>(QStringLiteral("dx"), 0);
float dy = np.get<float>(QStringLiteral("dy"), 0);
float x = np.get<float>(QStringLiteral("x"), 0);
float y = np.get<float>(QStringLiteral("y"), 0);
bool isSingleClick = np.get<bool>(QStringLiteral("singleclick"), false);
bool isDoubleClick = np.get<bool>(QStringLiteral("doubleclick"), false);
@ -233,12 +235,16 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np)
}
} else { // Is a mouse move event
if (dx || dy) {
POINT point;
if (GetCursorPos(&point)) {
return SetCursorPos(point.x + (int)dx, point.y + (int)dy);
} else {
return false;
}
} else if ((np.has(QStringLiteral("x")) || np.has(QStringLiteral("y")))) {
return SetCursorPos((int)x, (int)y);
}
}
return true;
}

View file

@ -92,6 +92,8 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np)
{
float dx = np.get<float>(QStringLiteral("dx"), 0);
float dy = np.get<float>(QStringLiteral("dy"), 0);
float x = np.get<float>(QStringLiteral("x"), 0);
float y = np.get<float>(QStringLiteral("y"), 0);
bool isSingleClick = np.get<bool>(QStringLiteral("singleclick"), false);
bool isDoubleClick = np.get<bool>(QStringLiteral("doubleclick"), false);
@ -196,8 +198,12 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np)
XFlush(display);
} else { // Is a mouse move event
if (dx || dy) {
QPoint point = QCursor::pos();
QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
} else if (np.has(QStringLiteral("x")) || np.has(QStringLiteral("y"))) {
QCursor::setPos(x, y);
}
}
return true;
}