[network/kdeconnect-android] src/main/java/org/kde/kdeconnect/plugins/mousepad: plugins/mousepad: Improve behavior of double tap drag

Albert Vaca Cintora <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 39b4d1002a10636006800857f358f78a8dc45fdf by Albert Vaca Cintora, on behalf of David Leppla-Weber.
Committed on 02/08/2026 at 20:01.
Pushed by albertvaka into branch 'master'.

plugins/mousepad: Improve behavior of double tap drag

Double tap drag relies on the behavior of
GestureDetector.OnDoubleTapListener to unconditionally start dragging on
the down event of the second tap. As a result, with double tap drag
enabled, it is not possible to send a double click event from the mouse
pad.

This commit improves on this behavior by only starting a drag if the
finger is moved after the 2nd down event by MinDraggingDistance2
(squared, to avoid sqrt operations in each move event for distance
calculation).

If the finger has moved less than the defined distance, the double click
event is sent instead.

M  +38   -13   src/main/java/org/kde/kdeconnect/plugins/mousepad/MousePadActivity.java

https://invent.kde.org/network/kdeconnect-android/-/commit/39b4d1002a10636006800857f358f78a8dc45fdf

diff --git a/src/main/java/org/kde/kdeconnect/plugins/mousepad/MousePadActivity.java b/src/main/java/org/kde/kdeconnect/plugins/mousepad/MousePadActivity.java
index c8ce6f9db..e502664fe 100644
--- a/src/main/java/org/kde/kdeconnect/plugins/mousepad/MousePadActivity.java
+++ b/src/main/java/org/kde/kdeconnect/plugins/mousepad/MousePadActivity.java
@@ -55,10 +55,14 @@ public class MousePadActivity
     private final static float MinDistanceToSendScroll = 2.5f; // touch gesture scroll
     private final static float MinDistanceToSendGenericScroll = 0.1f; // real mouse scroll wheel event
     private final static float StandardDpi = 240.0f; // = hdpi
+    private final static float MinDraggingDistance2 = 25.0f; // distance squared to move after
+                                                             // a double tap to start dragging
 
     private float mPrevX;
     private float mPrevY;
     boolean dragging = false;
+    boolean maybeDragging = false;
+    private float accumulatedDragDistance2 = 0.0f;
     private float mCurrentSensitivity;
     private float displayDpiMultiplier;
     private int scrollDirection = 1;
@@ -322,6 +326,12 @@ public class MousePadActivity
             }
         }
 
+        MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
+        if (plugin == null) {
+            finish();
+            return true;
+        }
+
         switch (actionType) {
             case MotionEvent.ACTION_DOWN:
                 mPrevX = event.getX();
@@ -331,24 +341,35 @@ public class MousePadActivity
                 float mCurrentX = event.getX();
                 float mCurrentY = event.getY();
 
-                MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
-                if (plugin == null) {
-                    finish();
-                    return true;
-                }
-
                 float deltaX = (mCurrentX - mPrevX) * displayDpiMultiplier * mCurrentSensitivity;
                 float deltaY = (mCurrentY - mPrevY) * displayDpiMultiplier * mCurrentSensitivity;
 
-                // Run the mouse delta through the pointer acceleration profile
-                mPointerAccelerationProfile.touchMoved(deltaX, deltaY, event.getEventTime());
-                mouseDelta = mPointerAccelerationProfile.commitAcceleratedMouseDelta(mouseDelta);
-
-                plugin.sendMouseDelta(mouseDelta.x, mouseDelta.y);
+                if (maybeDragging) {
+                    accumulatedDragDistance2 += deltaX*deltaX + deltaY*deltaY;
+                    if (accumulatedDragDistance2 >= MinDraggingDistance2) {
+                        maybeDragging = false;
+                        dragging = true;
+                        accumulatedDragDistance2 = 0.0f;
+                        plugin.sendSingleHold();
+                    }
+                } else {
+                    // Run the mouse delta through the pointer acceleration profile
+                    mPointerAccelerationProfile.touchMoved(deltaX, deltaY, event.getEventTime());
+                    mouseDelta = mPointerAccelerationProfile.commitAcceleratedMouseDelta(mouseDelta);
+
+                    plugin.sendMouseDelta(mouseDelta.x, mouseDelta.y);
+                }
 
                 mPrevX = mCurrentX;
                 mPrevY = mCurrentY;
 
+                break;
+            case MotionEvent.ACTION_UP:
+                if (doubleTapDragEnabled && maybeDragging) {
+                    maybeDragging = false;
+                    accumulatedDragDistance2 = 0.0f;
+                    plugin.sendDoubleClick();
+                }
                 break;
         }
         return true;
@@ -449,8 +470,7 @@ public class MousePadActivity
         }
         if (!dragging) {
             if (doubleTapDragEnabled) {
-                plugin.sendSingleHold();
-                dragging = true;
+                maybeDragging = true;
             } else {
                 plugin.sendDoubleClick();
             }
@@ -460,6 +480,11 @@ public class MousePadActivity
 
     @Override
     public boolean onDoubleTapEvent(MotionEvent e) {
+        if (e.getAction() == MotionEvent.ACTION_UP && maybeDragging) {
+            // Make sure we pass the event on to the general motion event handler which takes
+            // care of ending an eventual drag.
+            return false;
+        }
         return true;
     }
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.