[network/kdeconnect-kde/release/26.08] plugins/mousepad: Fix drag-and-drop on macos

Albert Vaca Cintora <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 966e709a65b1cfdc0235634de2085ef990c6162b by Albert Vaca Cintora.
Committed on 13/08/2026 at 20:05.
Pushed by albertvaka into branch 'release/26.08'.

Fix drag-and-drop on macos

(cherry picked from commit 5a32c78b6c83c047dc094d947681fed5468951e4)

M  +7    -0    plugins/mousepad/macosremoteinput.h
M  +24   -6    plugins/mousepad/macosremoteinput.mm

https://invent.kde.org/network/kdeconnect-kde/-/commit/966e709a65b1cfdc0235634de2085ef990c6162b

diff --git a/plugins/mousepad/macosremoteinput.h b/plugins/mousepad/macosremoteinput.h
index 2806e0869..3b7028d4b 100644
--- a/plugins/mousepad/macosremoteinput.h
+++ b/plugins/mousepad/macosremoteinput.h
@@ -8,6 +8,8 @@
 
 #include "abstractremoteinput.h"
 
+#include <QPoint>
+
 class MacOSRemoteInput : public AbstractRemoteInput
 {
     Q_OBJECT
@@ -17,4 +19,9 @@ public:
 
     bool handlePacket(const NetworkPacket &np) override;
     bool hasKeyboardSupport() override;
+
+private:
+    void setMousePos(const QPoint &pos);
+
+    bool m_leftButtonPressed = false;
 };
diff --git a/plugins/mousepad/macosremoteinput.mm b/plugins/mousepad/macosremoteinput.mm
index 49456e254..3367cae96 100644
--- a/plugins/mousepad/macosremoteinput.mm
+++ b/plugins/mousepad/macosremoteinput.mm
@@ -91,6 +91,7 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
             CGEventSetType(event, kCGEventLeftMouseUp);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
+            m_leftButtonPressed = false;
         } else if (isDoubleClick) {
             CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(point.x(), point.y()), kCGMouseButtonLeft);
             CGEventPost(kCGHIDEventTap, event);
@@ -108,26 +109,29 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
             CGEventSetType(event, kCGEventLeftMouseUp);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
-		} else if (isMiddleClick) {
+            m_leftButtonPressed = false;
+        } else if (isMiddleClick) {
             CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventOtherMouseDown, CGPointMake(point.x(), point.y()), kCGMouseButtonLeft);
             CGEventPost(kCGHIDEventTap, event);
             CGEventSetType(event, kCGEventOtherMouseUp);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
-		} else if (isRightClick) {
+        } else if (isRightClick) {
             CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventRightMouseDown, CGPointMake(point.x(), point.y()), kCGMouseButtonLeft);
             CGEventPost(kCGHIDEventTap, event);
             CGEventSetType(event, kCGEventRightMouseUp);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
-		} else if (isSingleHold) {
+        } else if (isSingleHold) {
             CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(point.x(), point.y()), kCGMouseButtonLeft);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
+            m_leftButtonPressed = true;
         } else if (isSingleRelease) {
             CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, CGPointMake(point.x(), point.y()), kCGMouseButtonLeft);
             CGEventPost(kCGHIDEventTap, event);
             CFRelease(event);
+            m_leftButtonPressed = false;
         } else if (isScroll) {
             CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, dy);
             CGEventPost(kCGHIDEventTap, event);
@@ -209,11 +213,11 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
 
         }
     } else { //Is a mouse move event
-         if (dx || dy) {
+        if (dx || dy) {
             QPoint point = QCursor::pos();
-            QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
+            setMousePos(QPoint(point.x() + (int)dx, point.y() + (int)dy));
         } else if (np.has(QStringLiteral("x")) || np.has(QStringLiteral("y"))) {
-            QCursor::setPos(x, y);
+            setMousePos(QPoint((int)x, (int)y));
         }
     }
     return true;
@@ -223,4 +227,18 @@ bool MacOSRemoteInput::hasKeyboardSupport() {
     return true;
 }
 
+void MacOSRemoteInput::setMousePos(const QPoint &pos)
+{
+    if (m_leftButtonPressed) {
+        // Moving the cursor via QCursor::setPos() with a button pressed does not
+        // generate a kCGEventLeftMouseDragged event, so without this apps never
+        // see a "mouse dragged" event and the mouse moves without dragging anything.
+        CGEventRef event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDragged, CGPointMake(pos.x(), pos.y()), kCGMouseButtonLeft);
+        CGEventPost(kCGHIDEventTap, event);
+        CFRelease(event);
+    } else {
+        QCursor::setPos(pos);
+    }
+}
+
 #include "moc_macosremoteinput.cpp"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.