From b7763fc8889c074ff2956dc58cd509f6a5dd91fc Mon Sep 17 00:00:00 2001 From: David Redondo Date: Mon, 24 Jun 2024 10:49:57 +0200 Subject: [PATCH] mousepad: Support setting the cursor to absolute positions --- plugins/mousepad/macosremoteinput.mm | 12 +++++++++--- plugins/mousepad/waylandremoteinput.cpp | 7 ++++++- plugins/mousepad/windowsremoteinput.cpp | 16 +++++++++++----- plugins/mousepad/x11remoteinput.cpp | 10 ++++++++-- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/plugins/mousepad/macosremoteinput.mm b/plugins/mousepad/macosremoteinput.mm index 22d8a881f..7a23769ac 100644 --- a/plugins/mousepad/macosremoteinput.mm +++ b/plugins/mousepad/macosremoteinput.mm @@ -71,6 +71,8 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np) float dx = np.get(QStringLiteral("dx"), 0); float dy = np.get(QStringLiteral("dy"), 0); + float x = np.get(QStringLiteral("x"), 0); + float y = np.get(QStringLiteral("y"), 0); bool isSingleClick = np.get(QStringLiteral("singleclick"), false); bool isDoubleClick = np.get(QStringLiteral("doubleclick"), false); @@ -138,7 +140,7 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np) bool alt = np.get(QStringLiteral("alt"), false); bool shift = np.get(QStringLiteral("shift"), false); bool super = np.get(QStringLiteral("super"), false); - + if (ctrl) { CGEventRef ctrlEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)kVK_Control, true); @@ -214,8 +216,12 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np) } } else { //Is a mouse move event - QPoint point = QCursor::pos(); - QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy); + 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; } diff --git a/plugins/mousepad/waylandremoteinput.cpp b/plugins/mousepad/waylandremoteinput.cpp index d1289a425..e6207fb61 100644 --- a/plugins/mousepad/waylandremoteinput.cpp +++ b/plugins/mousepad/waylandremoteinput.cpp @@ -210,6 +210,8 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np) const float dx = np.get(QStringLiteral("dx"), 0); const float dy = np.get(QStringLiteral("dy"), 0); + const float x = np.get(QStringLiteral("x"), 0); + const float y = np.get(QStringLiteral("y"), 0); const bool isSingleClick = np.get(QStringLiteral("singleclick"), false); const bool isDoubleClick = np.get(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 - s_session->iface->NotifyPointerMotion(s_session->m_xdpPath, {}, dx, dy); + 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; } diff --git a/plugins/mousepad/windowsremoteinput.cpp b/plugins/mousepad/windowsremoteinput.cpp index c7aa48835..f6f2a280a 100644 --- a/plugins/mousepad/windowsremoteinput.cpp +++ b/plugins/mousepad/windowsremoteinput.cpp @@ -64,6 +64,8 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np) { float dx = np.get(QStringLiteral("dx"), 0); float dy = np.get(QStringLiteral("dy"), 0); + float x = np.get(QStringLiteral("x"), 0); + float y = np.get(QStringLiteral("y"), 0); bool isSingleClick = np.get(QStringLiteral("singleclick"), false); bool isDoubleClick = np.get(QStringLiteral("doubleclick"), false); @@ -233,11 +235,15 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np) } } else { // Is a mouse move event - POINT point; - if (GetCursorPos(&point)) { - return SetCursorPos(point.x + (int)dx, point.y + (int)dy); - } else { - return false; + 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; diff --git a/plugins/mousepad/x11remoteinput.cpp b/plugins/mousepad/x11remoteinput.cpp index be42409ef..fa6ab1e00 100644 --- a/plugins/mousepad/x11remoteinput.cpp +++ b/plugins/mousepad/x11remoteinput.cpp @@ -92,6 +92,8 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np) { float dx = np.get(QStringLiteral("dx"), 0); float dy = np.get(QStringLiteral("dy"), 0); + float x = np.get(QStringLiteral("x"), 0); + float y = np.get(QStringLiteral("y"), 0); bool isSingleClick = np.get(QStringLiteral("singleclick"), false); bool isDoubleClick = np.get(QStringLiteral("doubleclick"), false); @@ -196,8 +198,12 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np) XFlush(display); } else { // Is a mouse move event - QPoint point = QCursor::pos(); - QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy); + 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; }